﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PMS.AuditClass
{
    public class CM_Audit
    {
        /// <summary>
        /// 报价单审核通过时将数据转储到生产表中
        /// </summary>
        /// <param name="total"></param>
        /// <param name="detail"></param>
        public static void QuotationPush(BD_ReviewTotal total, List<BD_ReviewDetail> detail)
        {
            //int reviewId = total.ID;
            //View_CM_Quotation quo = DALSession.Current.View_CM_QuotationDAL.GetListBy(u => u.ReviewId == reviewId).FirstOrDefault();
            //PM_ProductOrder pc = new PM_ProductOrder();
            //pc.ContractID = quo.ContractID;
            //pc.IsUrgent = "0";
            //pc.OrderDate = quo.Date;
            //pc.ReleaseDate = quo.ReleaseDate;
            //pc.FillPerson = quo.AddName;
            //pc.FillDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            //pc.Note = quo.Note;
            //pc.QuotationID = quo.ID;
            //pc.QuotationCode = quo.Code;
            //pc.SupplierID = quo.SupplierID;
            //pc.SupplierName = quo.SupName;
            //pc.CustomerID = quo.CustomerID;
            //pc.CustomerName = quo.ComName;
            //pc.ContractCode = quo.ContractCode;
            //pc.InvoiceAddress = quo.InvoiceAddress;
            //pc.ReceiveAddress = quo.Address;
            //pc.IsComplete = "0";
            //pc.CompleteDate = "";
            //pc.BeikuState = quo.ProductType == "1" ? "1" : "0";
            //int pcid = int.Parse(DALSession.Current.PM_ProductOrderDAL.AddModelReturnId(pc, "ID"));
            ////DALSession.Current.PM_ProductOrderDAL.SaveChanges();
            //List<CM_QuotationDetail> details = DALSession.Current.CM_QuotationDetailDAL.GetListBy(u => u.QuotationID == quo.ID).ToList();
            //for (int i = 0; i < details.Count; i++)
            //{
            //    PM_ProductOrderDetail de = new PM_ProductOrderDetail();
            //    de.Code = "";
            //    de.TotalId = pcid;
            //    de.QuoDetailId = details[i].ID;
            //    de.ProductCode = details[i].ProductCode;
            //    de.ProductName = details[i].ProductName;
            //    de.IsPureGas = details[i].IsPureGas;
            //    de.IsOccupy = "0";
            //    de.TechParams = details[i].TechParams;
            //    de.CusTechParams = details[i].CusTechParams;
            //    de.BottleVolume = details[i].BottleVolume;
            //    de.BottleCount = details[i].BottleCount;
            //    de.BottlePrice = details[i].BottlePrice;
            //    de.unit = details[i].unit;
            //    de.OrderCount = details[i].OrderCount;
            //    de.SinglePrice = details[i].SinglePrice;
            //    de.TotalPrice = details[i].TotalPrice;
            //    de.IsNewBottle = details[i].IsNewBottle;
            //    de.OrderCode = details[i].OrderCode;
            //    de.StockCode = details[i].StockCode;
            //    de.PurchaseType = details[i].PurchaseType;
            //    de.ApplyPerson = details[i].ApplyPerson;
            //    de.State = "0";
            //    de.ProductType = quo.ProductType;
            //    de.DetailNote = details[i].Note;               
            //    DALSession.Current.PM_ProductOrderDetailDAL.Add(de);
            //}
            //DALSession.Current.PM_ProductOrderDetailDAL.SaveChanges();
            ////更新报价单和订单状态
            //CM_Quotation cm = DALSession.Current.CM_QuotationDAL.GetListBy(u => u.ReviewId == reviewId).FirstOrDefault();
            //if (cm.State == "0")
            //{
            //    cm.State = "2"; //如果是报价单状态，更新为已订单
            //}
            //else if (cm.State == "1")
            //{
            //    cm.State = "3"; //如果是已合同状态，更新为已合同已订单
            //}
            //DALSession.Current.CM_QuotationDAL.ModifyBy(cm, p => p.ID == cm.ID, "State");
            //DALSession.Current.CM_QuotationDAL.SaveChanges();
        }
        public static void Reject(BD_ReviewTotal total, List<BD_ReviewDetail> detail)
        {
            Audit.ResetAuditDetail(total.ID, 0);
        }
    }
}